package com.daqian.chance.mybatis.tk.conf;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tk.mybatis.mapper.autoconfigure.SpringBootVFS;

import javax.sql.DataSource;


/**
 * @author: daqian
 * @date: 2019/7/10 19:41
 */
@Configuration
public class MybatisTkConfig {
    @Bean
    @ConditionalOnMissingBean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
        factory.setDataSource(dataSource);
        // 让enum的handler生效
        factory.setVfs(SpringBootVFS.class);
        return factory.getObject();
    }
}
